<?php
namespace app\api\controller\v1;

use think\facade\Db;

class Auto
{
    public function dianpu(){
        $param = request()->get();
        $param['module'] = 'dp_cyms';
        switch($param['action']){
            case 'reset':
        		Db::name('auto')->where('module',$param['module'])->update(['num'=>0]);
        		return json([
        			'status' => 1,
        			'msg' => '重置成功'
        		]);
        	break;

            case 'run':
                $auto = Db::name('auto')->where("module = '{$param['module']}' AND num < count")->find();
                if(empty($auto)){
        			return json([
	        			'status' => 0,
	        			'msg' => '今日任务全部完毕！'
	        		]);
        		}
                $row = Db::name($param['module'])->field('id,name,cityname')->where('is_show',0)->find();
    			if(empty($row)){
    				return json([
        				'status' => 0,
        				'msg' => '没有相关数据'
        			]);
    			}
                $r = Db::name($param['module'])->where('id',$row['id'])->update(['is_show'=>1,'show_time'=>time()]);
                if($r){
                    Db::name('auto')->where('module',$auto['module'])->inc('num')->update();
                }
                return json([
    				'status' => 1,
    				'msg' => $row['cityname'] . ' | ' . $row['name']
    			]);
            break;
        }
    }

    public function test(){
        $param = request()->get();
        dump($param);
    }
}